#include "Saw.h"
#include "AchievementManager.h"
#include "Camera.h"
#include "TinyXMLDan.h"

#include "Events\CSGD_EventSystem.h"

using namespace AchievementSystem;

// Constructor
Saw::Saw(void)
{
	objectID = "Saw";

	TinyXMLDan dan;
	anim = dan.Load("XML\\SawAnim.xml");
	anim.Play(true);

	this->SetCoolRate(1.0f);
	canBeGrappled = false;
}

// Destructor
Saw::~Saw(void)
{
}

void Saw::Update(float deltaTime)
{
	if(on == true)
	{
		anim.Update(deltaTime);

		if(this->CurTemp() == this->MinTemp())
			this->on = false;
	}
	else
	{
		if(this->CurTemp() >= this->MinTemp() * 0.5f)
			this->on = true;
	}

	HeatPhysics::Update(deltaTime);
}
void Saw::Render(void) const
{
	int a = 255, r = 255, g = 255, b = 255;

	if(this->CurTemp() < 0.0f)
	{
		r = g = (int)((this->CurTemp() / this->MaxTemp()) * 255.0f);
	}
	else if(this->CurTemp() > 0.0f)
	{
		g = b = (int)((this->CurTemp() / this->MinTemp()) * 255.0f);
	}

	int width = (int)(anim.GetCurrAnchorPoint().x - anim.GetCurrSourceRect().left);
	int height = (int)(anim.GetCurrAnchorPoint().y - anim.GetCurrSourceRect().top);
	anim.Render(
		(int)(positionX - Camera::GetInstance()->OffsetX() + width),
		(int)(positionY - Camera::GetInstance()->OffsetY() - height),
		1.0f, 1.0f, D3DCOLOR_ARGB(a, r, g, b));
}
void Saw::HandleCollision(GameObject& other, CollisionInfo& info)
{
	if(on == false)
		return;

	if(other.GetObjectID() == "Player")
	{
		AchievementManager::GetInstance().SendEvent("Kill Player", 1);
		CSGD_EventSystem::GetInstance()->SendEvent("KillPlayer", nullptr, nullptr, (void*)this);
	}
}